// Copyright (c) <2010> <Playdead>
// This file is subject to the MIT License as seen in the trunk of this repository
// Maintained by: <Kristian Kjems> <kristian.kjems+UnitySVN@gmail.com>

// This script includes common SVN related operations

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
#pragma warning disable 0219, 0414

public static class SVNUtility
{
    public static bool ChangesStoredInScene(GameObject go)
    {
        return (!IsPrefab(go, true, false, false) && !(EditorUtility.GetPrefabType(go) == PrefabType.ModelPrefab));
    }

    public static string GetAssetPath(GameObject go)
    {
        string assetpath = "";
        if (ChangesStoredInScene(go) )
        {
            return EditorApplication.currentScene;
        }
        else
        {
            return AssetDatabase.GetAssetPath(EditorUtility.GetPrefabParent(go));
        }        
    }

    public static bool IsPrefab(GameObject go) { return IsPrefab(go, true, true, true); }
    public static bool IsPrefab(GameObject go, bool includeRegular, bool includeModels, bool includeDisconnected)
    {
        PrefabType pbtype = EditorUtility.GetPrefabType(go);
        bool isPrefab =
            (includeRegular && pbtype == PrefabType.Prefab) ||
            (includeRegular && pbtype == PrefabType.PrefabInstance) ||
            (includeRegular && includeDisconnected && pbtype == PrefabType.DisconnectedPrefabInstance) ||
            (includeModels && pbtype == PrefabType.ModelPrefab) ||
            (includeModels && pbtype == PrefabType.ModelPrefabInstance) ||
            (includeModels && includeDisconnected && pbtype == PrefabType.DisconnectedModelPrefabInstance);
        return isPrefab;
    }
}
